import { type NextRequest, NextResponse } from "next/server"

export async function GET(request: NextRequest) {
  try {
    const searchParams = request.nextUrl.searchParams
    const userId = searchParams.get("userId")
    const page = searchParams.get("page") ? Number.parseInt(searchParams.get("page")!) : 1
    const limit = searchParams.get("limit") ? Number.parseInt(searchParams.get("limit")!) : 20

    // 模拟数据
    const songs = Array.from({ length: 20 }, (_, i) => ({
      id: i + 1,
      title: `Song Title ${i + 1}`,
      artist: `Artist ${(i % 5) + 1}`,
      album: `Album ${(i % 10) + 1}`,
      duration: 180 + i * 10,
      cover: `/placeholder.svg?height=300&width=300&text=Song+${i + 1}`,
      url: `/api/stream?songId=${i + 1}`,
    }))

    return NextResponse.json({
      data: songs,
      pagination: {
        page,
        limit,
        total: 100,
        totalPages: Math.ceil(100 / limit),
      },
    })
  } catch (error) {
    console.error("Error fetching user liked songs:", error)
    return NextResponse.json({ error: "Failed to fetch user liked songs" }, { status: 500 })
  }
}

export async function POST(request: NextRequest) {
  try {
    const body = await request.json()
    const { songId } = body

    return NextResponse.json({
      success: true,
      message: `Song ${songId} added to favorites`,
    })
  } catch (error) {
    console.error("Error adding song to favorites:", error)
    return NextResponse.json({ error: "Failed to add song to favorites" }, { status: 500 })
  }
}

export async function DELETE(request: NextRequest) {
  try {
    const body = await request.json()
    const { songId } = body

    return NextResponse.json({
      success: true,
      message: `Song ${songId} removed from favorites`,
    })
  } catch (error) {
    console.error("Error removing song from favorites:", error)
    return NextResponse.json({ error: "Failed to remove song from favorites" }, { status: 500 })
  }
}

